﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace AdoFramework
{

    class Program
    {
        static void Main(string[] args)
        {
            UpdateStudentTo();
        }

        public static void UpdateStudentTo()
        {
            DataSet dsXml = new DataSet();
            SqlTransaction tran = null;
            using (SqlConnection conn = new SqlConnection(DBConnString.DBConnStringExpress))
            {
                try
                {

                    SqlCommand cmd = conn.CreateCommand();
                    cmd.CommandText = @"SELECT * FROM sc";
                    cmd.CommandText = @"update sc set score3flo = '" + 12.666666661111111111 + "'";

                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    

                    conn.Open();
                    tran = conn.BeginTransaction(IsolationLevel.RepeatableRead);
                    cmd.Transaction = tran;
                    sda.Fill(dsXml);
                    dsXml.Tables[0].Rows[0][5] = 12.6666666611111122222;
                    if (dsXml.HasChanges())
                    {
                        sda.Update(dsXml.Tables[0].GetChanges());
                        dsXml.Tables[0].AcceptChanges();
                    }
                    cmd.ExecuteNonQuery();
                    tran.Commit();

                    dsXml.WriteXml(@"d:\xml.xml", XmlWriteMode.WriteSchema);
                }
                catch (Exception e)
                {
                    if (null != tran)
                    {
                        tran.Rollback();
                    }
                    throw e;
                }
            }
        }
        public static void ExpStudentToXml()
        {
            DataSet dsXml = new DataSet();
            SqlTransaction tran = null;
            using (SqlConnection conn = new SqlConnection(DBConnString.DBConnStringExpress))
            {
                try
                {

                    SqlCommand cmd = conn.CreateCommand();
                    cmd.CommandText = @"SELECT * FROM student";

                    SqlDataAdapter sda = new SqlDataAdapter(cmd);


                    conn.Open();
                    tran = conn.BeginTransaction(IsolationLevel.RepeatableRead);
                    cmd.Transaction = tran;

                    sda.Fill(dsXml);
                    tran.Commit();

                    dsXml.WriteXml(@"d:\xml.xml", XmlWriteMode.WriteSchema);
                }
                catch (Exception e)
                {
                    if (null != tran)
                    {
                        tran.Rollback();
                    }
                    throw e;
                }

            }
        }
    }
}
